<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>用户信息列表</title>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/page.js"></script>
</head>
<body>
	<h1 align="center">用户信息列表 -- 分页 +条件查询</h1>
	
	
	<form action="${pageContext.request.contextPath}/admin/queryAllUserInfoByPagerAndCond.do" method="get" style="text-align:center;margin-bottom:20px;">
		输入条件：<input type="text" name="cond" value="${param.cond }"/>
		<input type="submit" value="查询"/>
	</form>
	
	<table border="1" align="center" width="80%">
		<tr>
			<th>编号</th>
			<th>帐号</th>
			<th>姓名</th>
			<th>性别</th>
			<th>电话</th>
			<th>邮箱</th>
			<th>注册时间</th>
			<th>操作</th>	
		</tr>
		
		
		<c:choose>
			<c:when test="${empty requestScope.pager.data }">
				<tr align="center">
					<td colspan="8">数据为空</td>
				</tr>
			</c:when>
			
			<c:otherwise>
				<c:forEach items="${requestScope.pager.data }" var="user">
					<tr align="center">
						<td>${user.id }</td>
						<td>${user.username }</td>
						<td>${user.name }</td>
						<td>${user.sex }</td>
						<td>${user.phone }</td>
						<td>${user.email }</td>
						<td>
							<fmt:formatDate value="${user.regTime }" pattern="yyyy-MM-dd hh:mm"/>
						</td>
						<td>删除 | 查看</td>	
					</tr>
				</c:forEach>
			</c:otherwise>
			
		</c:choose>
		
	</table>
	
	
	<h3 align="center">
		当前页：${requestScope.pager.currentPage } &nbsp;&nbsp;
		总页数：${requestScope.pager.totalPageCount } &nbsp;&nbsp;
		
		<!-- 只有一页 -->
		<!-- 当前页是第一页 -->
		<!-- 当前页是最后一页 -->
		<!-- 当前页是中间页 -->
		
		
		<!-- 
			注意：分页导航有两种情况
				1）有条件
				2）无条件
		 -->
		
		<c:choose>
			<c:when test="${empty param.cond }">
				<c:choose>
					<c:when test="${requestScope.pager.currentPage==1 && requestScope.pager.currentPage==requestScope.pager.totalPageCount }">
						首页 上一页 下一页 尾页
					</c:when>
					
					<c:when test="${requestScope.pager.currentPage==1}">
						首页 上一页 
						<a href="${pageContext.request.contextPath }/admin/queryAllUserInfoByPagerAndCond.do?cp=${requestScope.pager.currentPage+1}">下一页</a>
						<a href="${pageContext.request.contextPath }/admin/queryAllUserInfoByPagerAndCond.do?cp=${requestScope.pager.totalPageCount}">尾页</a>
					</c:when>
					
					<c:when test="${requestScope.pager.currentPage==requestScope.pager.totalPageCount}">
						<a href="${pageContext.request.contextPath }/admin/queryAllUserInfoByPagerAndCond.do">首页</a>
						<a href="${pageContext.request.contextPath }/admin/queryAllUserInfoByPagerAndCond.do?cp=${requestScope.pager.currentPage-1}">上一页</a>
						下一页 尾页
					</c:when>
					
					
					<c:otherwise>
						<a href="${pageContext.request.contextPath }/admin/queryAllUserInfoByPagerAndCond.do?cp=1">首页</a>
						<a href="${pageContext.request.contextPath }/admin/queryAllUserInfoByPagerAndCond.do?cp=${requestScope.pager.currentPage-1}">上一页</a>
						<a href="${pageContext.request.contextPath }/admin/queryAllUserInfoByPagerAndCond.do?cp=${requestScope.pager.currentPage+1}">下一页</a>
						<a href="${pageContext.request.contextPath }/admin/queryAllUserInfoByPagerAndCond.do?cp=${requestScope.pager.totalPageCount}">尾页</a>
					</c:otherwise>
				</c:choose>
			</c:when>
			
			<c:otherwise>
				<c:choose>
					<c:when test="${requestScope.pager.currentPage==1 && requestScope.pager.currentPage==requestScope.pager.totalPageCount }">
						首页 上一页 下一页 尾页
					</c:when>
					
					<c:when test="${requestScope.pager.currentPage==1}">
						首页 上一页 
						<a href="${pageContext.request.contextPath }/admin/queryAllUserInfoByPagerAndCond.do?cp=${requestScope.pager.currentPage+1}&cond=${param.cond}">下一页</a>
						<a href="${pageContext.request.contextPath }/admin/queryAllUserInfoByPagerAndCond.do?cp=${requestScope.pager.totalPageCount}&cond=${param.cond}">尾页</a>
					</c:when>
					
					<c:when test="${requestScope.pager.currentPage==requestScope.pager.totalPageCount}">
						<a href="${pageContext.request.contextPath }/admin/queryAllUserInfoByPagerAndCond.do&cond=${param.cond}">首页</a>
						<a href="${pageContext.request.contextPath }/admin/queryAllUserInfoByPagerAndCond.do?cp=${requestScope.pager.currentPage-1}&cond=${param.cond}">上一页</a>
						下一页 尾页
					</c:when>
					
					
					<c:otherwise>
						<a href="${pageContext.request.contextPath }/admin/queryAllUserInfoByPagerAndCond.do?cp=1&cond=${param.cond}">首页</a>
						<a href="${pageContext.request.contextPath }/admin/queryAllUserInfoByPagerAndCond.do?cp=${requestScope.pager.currentPage-1}&cond=${param.cond}">上一页</a>
						<a href="${pageContext.request.contextPath }/admin/queryAllUserInfoByPagerAndCond.do?cp=${requestScope.pager.currentPage+1}&cond=${param.cond}">下一页</a>
						<a href="${pageContext.request.contextPath }/admin/queryAllUserInfoByPagerAndCond.do?cp=${requestScope.pager.totalPageCount}&cond=${param.cond}">尾页</a>
					</c:otherwise>
				</c:choose>
			</c:otherwise>
		</c:choose>
		
		
		
		&nbsp;&nbsp;
		<input type="text" id="cp" style="width:30px" value="${param.cp }"/>
		<button type="button" onclick="goToPageAndCond('${pageContext.request.contextPath}','${param.cond }')">GO</button>
		
		
	</h3>
	
	
	<h1 align="center">
		<a href="${pageContext.request.contextPath }/admin/index.jsp">
			返回
		</a>
	</h1>
	
	
	
	
	
	
</body>
</html>